/*******************************************************************************
 * Copyright (c) 2008 L.Carbonnaux.
 *******************************************************************************/

package org.lcx.taskvision.ui.preferences;


import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.lcx.taskvision.core.ITaskVisionConstants;
import org.lcx.taskvision.core.TaskVisionCorePlugin;

/**
 * @author Laurent Carbonnaux
 */
public class TaskVisionPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
	
	public static final String ID = "org.lcx.scrumvision.ui.preferences";

	private Button unuseFibonacci;
	
	private Button updateAllTask;
	
	public TaskVisionPreferencePage() {
		super();
		setPreferenceStore(TaskVisionCorePlugin.getDefault().getPreferenceStore());
	}

	@Override
	protected Control createContents(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout(1, false);
		container.setLayout(layout);

		Label label = new Label(container, SWT.NULL);
		label.setText(Messages.SVPreferencePage_label);
		
		updateAllTask = new Button(container, SWT.CHECK);
		updateAllTask.setText(Messages.SVPreferencePage_update_all_rem);
		updateAllTask.setSelection(getPreferenceStore().getBoolean(ITaskVisionConstants.PREF_UPDATE_ALL_TASK));

		unuseFibonacci = new Button(container, SWT.CHECK);
		unuseFibonacci.setText(Messages.SVPreferencePage_use_fibonacci);
		unuseFibonacci.setSelection(getPreferenceStore().getBoolean(ITaskVisionConstants.PREF_USE_FIBONACCI));
		
		return container;
	}

	public void init(IWorkbench workbench) {
		// ignore		
	}
	
	@Override
	public boolean performOk() {
		getPreferenceStore().setValue(ITaskVisionConstants.PREF_USE_FIBONACCI, unuseFibonacci.getSelection());
		getPreferenceStore().setValue(ITaskVisionConstants.PREF_UPDATE_ALL_TASK, updateAllTask.getSelection());
		return true;
	}

	@Override
	public boolean performCancel() {
		unuseFibonacci.setSelection(getPreferenceStore().getBoolean(ITaskVisionConstants.PREF_USE_FIBONACCI));
		updateAllTask.setSelection(getPreferenceStore().getBoolean(ITaskVisionConstants.PREF_UPDATE_ALL_TASK));
		return true;
	}
	
	@Override
	public void performDefaults() {
		super.performDefaults();
		unuseFibonacci.setSelection(getPreferenceStore().getDefaultBoolean(ITaskVisionConstants.PREF_USE_FIBONACCI));
		updateAllTask.setSelection(getPreferenceStore().getDefaultBoolean(ITaskVisionConstants.PREF_UPDATE_ALL_TASK));
	}	

}
